//队列
module.exports = function(args){
    var _this = this;
    args = args || {};
    this.typeOf = 'Item';
    this.item = [];
    this.length = 0;
    this.flog = 0;
    this.max = args.max || 1;
    this.actionLength = 0;
    this.begined = false;
    this._push = function (fn,index) {
      if(index != undefined && this.length){
        this.item.splice(this.flog + index,0,fn);
      }else{
        this.item.push(fn);
      }
      this.length++;
      if (this.begined && this.actionLength < this.max) this._do();
    }
    this.value = undefined;
    this._do = function () {
      if(!this.begined) this.begined = true;
      if(this.length == 0) return false;
      this.actionLength++;
      this.length--;
      this.item[this.flog](function (value) {
        setTimeout(function(){
          _this.value = value;
          _this.actionLength--;
          if (_this.length > 0) _this._do();
        },100)
      },_this.value);
      this.item[this.flog] = null;
      this.flog++;
    }
}